package com.lingxu.base.system.dict.controller;

import java.util.Arrays;
import java.util.Date;

import javax.annotation.Resource;

import com.lingxu.base.system.dict.model.HolidayReq;
import io.swagger.annotations.ApiParam;

import com.lingxu.base.common.api.vo.Result;
import com.lingxu.base.common.api.vo.ResultOne;
import com.lingxu.base.common.annotation.Encrypt;
import com.lingxu.base.system.dict.entity.Holiday;
import com.lingxu.base.system.dict.service.IHolidayService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 * @Description: 数据字典-节假日
 * @Author: 朱家池
 * @Date:   2023-05-16
 * @Version: V1.0.1
 */
@Slf4j
@Api(tags="数据字典-节假日")
@RestController
@RequestMapping("/system/holiday")
public class HolidayController{
	@Resource
	private IHolidayService holidayService;
	
	/**
	 * 分页列表查询
	 *
	 * @param holidayReq
	 * @return
	 */
	@ApiOperation(value="数据字典-节假日-分页列表查询", notes="数据字典-节假日-分页列表查询")
	@PostMapping(value = "/list")
	public ResultOne<Holiday> queryPageList(@RequestBody HolidayReq holidayReq) {
		Page<Holiday> page = new Page<Holiday>(holidayReq.getPageNo(), holidayReq.getPageSize());
		IPage<Holiday> pageList = holidayService.queryPageList(page, holidayReq);
		return ResultOne.ok(pageList);
	}
	
	/**
	 * 添加
	 *
	 * @param holiday
	 * @return
	 */
	@ApiOperation(value="数据字典-节假日-添加", notes="数据字典-节假日-添加")
	@PutMapping(value = "/add")
	public Result<?> add(@Encrypt @RequestBody Holiday holiday) {
		holiday.setAddTime(new Date());
		holidayService.save(holiday);
		return Result.ok("添加成功！");
	}
	
	/**
	 * 编辑
	 *
	 * @param holiday
	 * @return
	 */
	@ApiOperation(value="数据字典-节假日-编辑", notes="数据字典-节假日-编辑")
	@PostMapping(value = "/edit")
	public Result<?> edit(@Encrypt @RequestBody Holiday holiday) {
		holidayService.updateById(holiday);
		return Result.ok("编辑成功!");
	}

	
	/**
	 * 批量删除
	 *
	 * @param ids
	 * @return
	 */
	@ApiOperation(value="数据字典-节假日-批量删除", notes="数据字典-节假日-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids")@ApiParam(value = "主键(多个用逗号','隔开)",required = true) String ids) {
		this.holidayService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.ok("删除成功！");
	}

}
